# -*- coding:utf-8 -*-
import uuid
import json
import requests
import multiprocessing
import os
import time

def update_progess(data):
    try:
        url = 'http://127.0.0.1:23412/TestUrl'
        s = json.dumps(data)
        r = requests.post(url, data=s)
        # print(r.text)
    except:
        pass

def new_progess():
    text = "----in 子进程 pid=%d ,父进程的pid=%d---" % (os.getpid(), os.getppid())
    print(text)
    d = {
        'uuid': str(uuid.uuid5(uuid.NAMESPACE_DNS, text)),
        'text': text,
        'step': 0,
        'total': 100
    }
    
    step = 0
    for i in range(101):
        d['step'] = step
        step += 1
        update_progess(d)
        time.sleep(1)

if __name__ == '__main__':
    pool = multiprocessing.Pool(processes = 3)
    for i in range(3):
        msg = "hello %d" %(i)
        pool.apply_async(new_progess)   #维持执行的进程总数为processes，当一个进程执行完毕后会添加新的进程进去
    
    pool.close()
    pool.join()   #调用join之前，先调用close函数，否则会出错。执行完close后不会有新的进程加入到pool,join函数等待所有子进程结束